<?php defined('SYSPATH') or die('No direct access allowed.');

/**
 * 微信小程序处理过滤函数
 * Class Model_Api_Standard_Xcx
 */
class Model_Api_Standard_Xcx
{

    function filter_content($content)
    {
        $pattern = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.jpeg]))[\'|\"].*?[\/]?>/i";
        $content = preg_replace_callback(
            $pattern,
            function ($ma) {
                $newUrl = $ma[1];
                if (strpos($ma[1], 'http') === false) {
                    $newUrl = Model_Api_Standard_System::reorganized_resource_url($newUrl);
                }
                return str_replace($ma[1], $newUrl, $ma[0]);
            }, $content);
        return $content;
    }

}